package com.chagee.store.operation.server.service;

import com.chagee.base.utils.*;
import com.alibaba.fastjson.JSON;
import com.chagee.store.operation.api.request.AcceptanceOrderRequest;
import com.chagee.store.operation.api.request.AcceptanceRequest;
import com.chagee.store.operation.server.component.StoreIssueNoticeComponent;
import com.chagee.store.operation.server.config.StoreIssueNoticeConfig;
import com.chagee.store.operation.server.event.service.TaskExecutionBaseService;
import com.chagee.store.operation.server.hadler.StoreIssueNotice;
import com.chagee.store.operation.server.model.param.*;
import com.chagee.store.operation.server.model.vo.QueryStoreTaskResponse;
import com.chagee.store.operation.server.model.vo.ScanResponse;
import com.chagee.store.operation.server.model.vo.StoreMonthOrderVO;
import com.chagee.store.operation.server.model.vo.StoreOderInfoVO;
import com.chagee.store.operation.server.service.biz.StoreAppSweepBizService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author : hk
 * @Date : 2024/7/31
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class StoreAppSweepService {

	@Resource
	private TaskExecutionBaseService taskExecutionBaseService;

	@Resource
	private StoreAppSweepBizService storeAppSweepBizService;

	@Resource
	private StoreIssueNoticeConfig issueNoticeConfig;

	public boolean sendMessage(StoreIssueNoticeParam param) {

		String appId = issueNoticeConfig.getAppId();
		String h5Url = issueNoticeConfig.getH5Url();
		String domain = issueNoticeConfig.getDomain();
		String lkTargetUrl = issueNoticeConfig.getLkTargetUrl();
		String pcDomain = issueNoticeConfig.getPcDomain();
		String pcUrl = issueNoticeConfig.getPcUrl();
		StoreIssueNotice notice = StoreIssueNoticeComponent.notice(param, appId, h5Url, domain, lkTargetUrl, pcDomain, pcUrl, taskExecutionBaseService).issueNotice();

		log.info("工单异常通知发消息给iot,发送消息{}", JSON.toJSONString(notice));
		boolean response = storeAppSweepBizService.sendMessage(notice);
		return response;
	}

	public PaginationData<QueryStoreTaskResponse> queryList(PaginationRequest<StoreAppSweepQueryParam> request) {
		return storeAppSweepBizService.queryList(request);
	}

	public PaginationData<QueryStoreTaskResponse> queryOrderTaskList(PaginationRequest<OrderTaskListParam> request) {
		return storeAppSweepBizService.queryOrderTaskList(request);
	}

	/**
	 * 门店本月单据状态详情
	 *
	 * @param param
	 * @return
	 */
	public StoreMonthOrderVO storeMonthOrder(MonthOrderParam param) {
		StoreMonthOrderVO storeMonthOrderVO = storeAppSweepBizService.storeMonthOrder(param);
		return storeMonthOrderVO;
	}

	/**
	 * 门店最近打烊工单日期
	 *
	 * @param param
	 * @return
	 */
	public String queryOrderDate(StoreWordInfoParam param) {
		String orderDate = storeAppSweepBizService.queryOrderDate(param);
		return orderDate;
	}

	/**
	 * 打烊任务工单
	 *
	 * @param queryParam
	 * @return
	 */
	public List<StoreOderInfoVO> storeOrder(PaginationRequest<StoreAppSweepQueryParam> queryParam) {
		List<StoreOderInfoVO> response = storeAppSweepBizService.storeOrder(queryParam);
		return response;
	}

	public StoreOderInfoVO queryOrderDetail(QueryOrderDetailParam queryParam){
		StoreOderInfoVO response = storeAppSweepBizService.queryOrderDetail(queryParam);
		return response;
	}

	public QueryStoreTaskResponse taskDetail(StoreTaskInfoRequest request) {
		return storeAppSweepBizService.taskDetail(request);
	}

	public HttpResponse<ScanResponse> taskAcceptance(AcceptanceRequest queryParam) {
		return HttpResponseUtil.success(storeAppSweepBizService.taskAcceptance(queryParam));
	}

	public Boolean orderAcceptance(AcceptanceOrderRequest request) {
		Boolean response = storeAppSweepBizService.orderAcceptance(request);
		return response;
	}

}
